package cn.virens.common.mybatis.dynamic_table;

import io.mybatis.provider.EntityColumn;
import io.mybatis.provider.EntityColumnFactory;
import io.mybatis.provider.EntityField;
import io.mybatis.provider.EntityTable;
import org.dromara.hutool.core.text.StrUtil;

import java.util.List;
import java.util.Optional;

public class MysqlEntityColumnFactory implements EntityColumnFactory {

    @Override
    public Optional<List<EntityColumn>> createEntityColumn(EntityTable entityTable, EntityField field, Chain chain) {
        return chain.createEntityColumn(entityTable, field).map(ecs -> ecs.stream().peek(item -> {
            item.column(StrUtil.wrapIfMissing(item.column(), "`", "`"));
        }).toList());
    }

    @Override
    public int getOrder() {
        return 1;
    }

}
